package com.example.schooljava.controller;


import com.example.schooljava.pojo.dto.StudentsDTO;
import com.example.schooljava.pojo.entity.Student;
import com.example.schooljava.pojo.bo.StudentsBO;
import com.example.schooljava.service.impl.StudentServiceImpl;
import com.example.schooljava.util.DTOtoBO;
import com.example.schooljava.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LDH
 * @since 2022/08/11
 */
@RestController
@RequestMapping("/school/student")
@Api(tags = "学生模块")
public class StudentController {

    @Autowired
    private StudentServiceImpl studentService;
    @Autowired
    private DTOtoBO dtOtoBO;


    @ApiOperation(value = "学生注册",notes = "<span style='color:red;'>详细描述：</span>&nbsp;学生注册接口，测试用")
    @PostMapping
    public Result stuRegister(@RequestBody Student student){
        return studentService.register(student);
    }

    @ApiOperation(value = "获取所有学生信息",notes = "<span style='color:red;'>详细描述：</span>&nbsp;学校管理人员获取全校所有学生信息")
    @PostMapping(value = "/getAll",name = "校长")
    public Result findAllStudents(@RequestBody StudentsDTO studentsDTO){
        StudentsBO studentsBO = new StudentsBO();
        return studentService.findAllStudents((StudentsBO) dtOtoBO.copyPro(studentsDTO,studentsBO));
    }

    @ApiOperation(value = "删除学生信息",notes = "<span style='color:red;'>详细描述：</span>&nbsp;学校管理人员删除学生信息")
    @DeleteMapping(name = "校长")
    public Result delStudents(@RequestBody ArrayList<String> list){
        return studentService.delStudent(list);
    }
}
